import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;

public class Pirate extends JFrame {
	private static final long serialVersionUID = 1L;	
	private JTextField txtSearch;
	private JTable tblResult;

	public Pirate() {
		initForm();
		initUI();
	}
	
	/*
	 * Initializes the form
	 */
	private final void initForm() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch(Exception e) {
			System.out.println("Error setting native LAF: " + e);
		}
		setTitle("Pirate");
		setLocationRelativeTo(null);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(684, 412);
		setMinimumSize(new Dimension(600, 350));
	}
	
	/*
	 * Initializes the UI components
	 */
	private final void initUI() {
		// Main panel
		JPanel pnlMain = new JPanel();
		pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.Y_AXIS));
		getContentPane().add(pnlMain);
		
		
		// Search panel
		JPanel pnlSearch = new JPanel();
		BorderLayout pnlSearchLayout = new BorderLayout();
		pnlSearchLayout.setHgap(2);
		pnlSearch.setLayout(pnlSearchLayout);
		pnlSearch.setMaximumSize(new Dimension(Integer.MAX_VALUE, 0));
		pnlSearch.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
		
		txtSearch = new JTextField();
		txtSearch.setFont(new Font("SansSerif", Font.PLAIN, 16));
		txtSearch.setBorder(BorderFactory.createLineBorder(Color.GRAY));
		pnlSearch.add(txtSearch, BorderLayout.CENTER);
		
		JButton btnSearch = new JButton("Search");
		btnSearch.setPreferredSize(new Dimension(100, 26));
		btnSearch.setMinimumSize(new Dimension(100, 26));
		pnlSearch.add(btnSearch, BorderLayout.EAST);

		
		// Result panel
		ArrayList<Song> data = new ArrayList<Song>();
		data.add(new Song(1, "Michael Jackson", "Billie Jean", 641, 45334534));
		data.add(new Song(1, "Michael Jackson", "Smooth Criminal", 431, 87785456));
		data.add(new Song(1, "Blue 5", "Billie Jean", 312, 98645131));
		data.add(new Song(1, "Det brune punktum", "Hver dag", 123, 32545618));
		tblResult = new JTable(new ResultTableModel(data));
		tblResult.setFillsViewportHeight(true);

		JScrollPane pnlTable = new JScrollPane(tblResult);
		pnlTable.setBorder(null);
		
		JPanel pnlResult = new JPanel();
		pnlResult.setLayout(new BorderLayout());
		pnlResult.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
		pnlResult.add(pnlTable, BorderLayout.CENTER);
		
		
		// Progress bar
		JProgressBar pbProgress = new JProgressBar();
		pbProgress.setPreferredSize(new Dimension(0, 20));
		pbProgress.setMinimumSize(new Dimension(0, 20));

		JPanel pnlProgress = new JPanel();
		pnlProgress.setLayout(new BorderLayout());
		pnlProgress.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
		pnlProgress.add(pbProgress, BorderLayout.CENTER);
		
		
						
		// Add to the main panel
		pnlMain.add(pnlSearch);
		pnlMain.add(pnlResult);
		pnlMain.add(pnlProgress);
	}
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Pirate p = new Pirate();
				p.setVisible(true);
			}
		});
	}

}
